<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>regist</title>
</head>
<body>
<form action="" method="post">
    <input name="userName">
    <input type="submit" name="submit" value="yes">
</form>
<%
    String submit=request.getParameter("submit");
    String userName=request.getParameter("userName");
    if("yes".equals(submit)){
        List<String> users=(List<String>) application.getAttribute("users");
        if(users==null)
            users=new ArrayList<>();

        for(String user:users){
            if(userName.equals(user)) {
//                out.println("添加失败："+userName);
                return;
            }
        }
//        out.println("添加成功："+userName);
        users.add(userName);
        application.setAttribute("users",users);
        response.sendRedirect("user.jsp");
    }else{
//        out.println("添加失败："+userName+",submit="+submit);
    }
%>
</body>
</html>
